/**
 * 
 */
package com.login.mng;

import java.sql.CallableStatement;
import java.util.HashMap;
import java.util.List;
import com.data.mng.Dao;
import com.msg.mng.MessageStore;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

/**
 * @author Administrator
 *
 */
public class LoginAction implements Action {
	private MessageStore messageStore;
	private String password="";
	private String username="";
	
	public String execute()throws Exception{
		Dao d = new Dao();
		CallableStatement c = d.getCallableStatement("Call proc_getUserInfo(?)");

		c.setString("name", "admin");
		List<HashMap<String, Object>> ret = d.execQuery(c);
		if (ret.size() < 1) {
			// user not exist
			return "failed";
		} else if (ret.size() == 1) {
			String pass = (String) ret.get(0).get("password");
			if (pass.equals(password)) {
				ActionContext.getContext().getSession().put("user", username);
				// data.getBook()
				messageStore = new MessageStore();
				messageStore.setUserName(this.username);
				return "success";
			}
		} else {
			return "failed";
		}
		return "failed";
	}

	/**
	 * @return the messageStore
	 */
	public MessageStore getMessageStore() {
		return messageStore;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * @param messageStore the messageStore to set
	 */
	public void setMessageStore(MessageStore messageStore) {
		this.messageStore = messageStore;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @param username the username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}
}
